package com.s3.khospitalds.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.s3.khospitalds.common.R;
import com.s3.khospitalds.common.ResponseEntity;
import com.s3.khospitalds.entity.Hasnurse;
import com.s3.khospitalds.entity.Storage;
import com.s3.khospitalds.service.StorageService;
import com.s3.khospitalds.service.impl.StorageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xw
 * @CreateTime: 2025/2/28
 * @Description: 药库信息表
 * @Version: 1.0
 */
@RestController
@CrossOrigin(origins = "*")
public class StorageController {
    @Autowired
    private StorageServiceImpl storageService;
    @GetMapping("/getAllStorage")
    public R getAllStorage() {
        return new R().addData("list",storageService.list());
    }
    @GetMapping("/getLimitStorage")
    public R getLimitStorage(Integer pageNum, Integer pageSize,String name) {
        pageNum = pageNum == null ? 1 : pageNum;
        pageSize = pageSize == null ? 10 : pageSize;
        name = name == null ? "" : name;
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //模糊查询
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",name);
        //使用分页查询
        List<Storage> storages = storageService.list(queryWrapper);
        //创建分页的对象
        PageInfo<Storage> pageInfo = new PageInfo<>(storages);
        return new R().addData("limit",pageInfo);
    }
    @GetMapping("/getStorageLikeName/{name}")
    public R findByName(@PathVariable("name") String name){
        return new R().addData("list",storageService.findByName(name));
    };
    @PostMapping("/insertStorage")
    public R insertStorage(@RequestBody Storage storage){
        return new R().addData("bol",storageService.insertStorage(storage));
    }
}
